package common;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

/**
 * Implements the syntax needed for communication with the server
 * A Message firstly has no sender/recipient. The message comes from a server
 * For messages between Users or User/Server communication we implemented
		UserMessage
		PrivateUserMessage
		
	Frederic's syntax:
	I don't use expéditeur (recipient) in this upper class
	MESSAGE --- expéditeur --- type (text, image, file, list) --- message ou contenu (fichiers, images, ...)
	
	----
	I don't use this. This simply is provided by the isPrivate flag
	// MESSAGE_PRIVE --- expéditeur --- type (string, image, file, list) --- message ou contenu (fichiers, images, ...)
	I don't use this. This simply is a content type LIST
	// LIST --- contenu (liste des users bloqués ou que je bloque)
 * 
 * @author Martina Willig
 *
 */
public class Message {
	/**
	 * Defines a content type
	 * @see MessageContentType
	 */
	protected String content;
	protected MessageContentType contenttype;
	protected boolean isPrivate = false;
	protected String recipient = null; // if null, recipients are all connected buddies
	protected String sender = null; // if null, message comes from server
	
	public void setContenttype(MessageContentType contenttype) {
		this.contenttype = contenttype;
	}
	public MessageContentType getContenttype() {
		return contenttype;
	}
	public void setPrivate(boolean isPrivate) {
		this.isPrivate = isPrivate;
	}
	public boolean isPrivate() {
		return isPrivate;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getContent() {
		return content;
	}
	
	public void setRecipient(String recipient) {
		this.recipient = recipient;
	}
	public String getRecipient() {
		return recipient;
	}
	public void setSender(String sender) {
		this.sender = sender;
	}
	public String getSender() {
		return sender;
	}
	
	/**
	 * Parse this message a a string understandable by the server
	 * MESSAGE --- expéditeur --- type (text, image, file, list) --- message ou contenu (fichiers, images, ...
	 * @return
	 */
	public String getParsedCommandString(){
		StringBuilder sb = new StringBuilder();
		String seperator = "|#";
		sb.append("MESSAGE"+seperator);
		if(this.sender != null){
			sb.append(this.getSender());
		} else{
			sb.append("all");
		}
		sb.append(this.getContenttype().toString()+seperator);
		sb.append(this.getContent());
		return sb.toString();
	}
	
	/**
	 * TODO implement
	 * @param message
	 * @return 
	 */
	public static Message parse(String message){
		return new Message();
	}
	
}
